package com.assessment.repository.impl;

import com.assessment.mapper.AssessmentRecordMapper;
import com.assessment.model.entity.AssessmentRecord;
import com.assessment.repository.AssessmentRecordRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * 评测记录仓储实现类
 */
@Repository
public class AssessmentRecordRepositoryImpl implements AssessmentRecordRepository {

    @Autowired
    private AssessmentRecordMapper recordMapper;

    @Override
    public boolean saveRecord(AssessmentRecord record) {
        return recordMapper.insert(record) > 0;
    }

    @Override
    public boolean batchSaveRecords(List<AssessmentRecord> records) {
        // MyBatis-Plus不直接支持批量插入，这里简化处理
        for (AssessmentRecord record : records) {
            if (recordMapper.insert(record) <= 0) {
                return false;
            }
        }
        return true;
    }

    @Override
    public List<AssessmentRecord> getRecordsByRelationId(Integer relationId) {
        return recordMapper.findByRelationId(relationId);
    }

    @Override
    public List<AssessmentRecord> getTeacherRecords(Integer teacherId, Integer periodId) {
        return recordMapper.findTeacherRecords(teacherId, periodId);
    }

    @Override
    public BigDecimal calculateTeacherAvgScore(Integer teacherId, Integer periodId) {
        return recordMapper.calculateAvgScore(teacherId, periodId);
    }

    @Override
    public BigDecimal calculateCategoryAvgScore(Integer teacherId, Integer periodId, Integer categoryId) {
        return recordMapper.calculateCategoryAvgScore(teacherId, periodId, categoryId);
    }
}
